/**
 * Created by wangyg 
 * on 2017/7/6 11:21
 */
import java.util.*;

public class TestShuffle {

	public static void main(String[] args) {
		int nums = 2;
		String[] users = new String[]{
				"test0", "test1", "test2", "test3", "test4", "test5", "test6", "test7", "test8", "test9",
				"test10", "test11", "test12", "test13", "test14", "test15", "test16", "test17", "test18", "test19",
				"test20", "test21", "test22", "test23", "test24", "test25", "test26", "test27", "test28", "test29",
				"test30", "test31", "test32", "test33", "test34", "test35", "test36", "test37", "test38", "test39",
				"test40", "test41", "test42", "test43", "test44", "test45", "test46", "test47", "test48", "test49",
		};
		lottery(users, nums);
	}

	public static void lottery(String[] users, int nums){
		List<String> userList = Arrays.asList(users);
		//乱序
		Collections.shuffle(userList);
		Random random = new Random();
		int i = 0;
		Set<Integer> set = new HashSet<>(nums);
		do {
			int nextInt = random.nextInt(userList.size());
			if(!set.contains(nextInt)){
				set.add(nextInt);
				i++;
			}
		} while (i < nums);
		System.out.println("============中奖名单============");
		for (Integer num : set) {
			System.out.println(userList.get(num));
		}
	}

}